package com.postaop.hntl.front.iso8583;

import java.util.BitSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.enlorenz.common.util.CommonContants;

/**
 * Iso报文消息对象
 * @author Karma
 */
public class IsoMessage {
	//报文头
	private String isoHead;
	//消息类型
	private String msgType;
	//位图集合
	private BitSet bitSet=new BitSet();
	
	private Map<Integer,IsoMessageDataWrapper> fieldDataMap
	=new TreeMap<Integer, IsoMessageDataWrapper>();
	
	public void setFieldValue(Integer index,String value){
		IsoMessageDataWrapper dataWrapper=new IsoMessageDataWrapper();
		dataWrapper.setValue(value);
		fieldDataMap.put(index, dataWrapper);
		bitSet.set(index);
	}
	
	//获取消息描述
	public String getIsoMsgDesc(){
		//获取所有的域索引
		Set<Integer> indexSet=getIndexSet();
		StringBuffer msg=new StringBuffer();
		for(Integer index:indexSet){
			String stringValue=getFiledValue(index);
			String tmp="INX:【%s】:【%s】";
			String print=String.format(tmp, index,stringValue);
			msg.append(print);
			msg.append(CommonContants.WRAP_SYMBOL);
		}
		return msg.toString();	
	}
	
	public String getFiledValue(Integer index){
		IsoMessageDataWrapper wrapper=fieldDataMap.get(index);
		if(null == wrapper){
			return null;
		}
		return wrapper.getValue();
	}
	/**
	 * 获取索引集合
	 * @return
	 */
	public Set<Integer> getIndexSet(){
		return fieldDataMap.keySet();
	}
	/**
	 * 获取位图集合
	 * @return
	 */
	public BitSet getBitSet() {
		return bitSet;
	}

	public String getMsgType() {
		return msgType;
	}

	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}

	public String getIsoHead() {
		return isoHead;
	}

	public void setIsoHead(String isoHead) {
		this.isoHead = isoHead;
	}
	
}
